package spring;

import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericApplicationContext;

/**
 * Created by sheting on 10/22/2017
 */
public class HelloWorld {
    public void sayHello() {
        System.out.println("Hello World");
    }

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
        HelloWorld helloWorld2 = context.getBean("helloWorld2", HelloWorld.class);
        helloWorld2.sayHello();

        HelloWorld helloWorld = context.getBean("helloWorld", HelloWorld.class);
        helloWorld.sayHello();
        System.out.println(helloWorld == helloWorld2);
        GenericApplicationContext context2 = new GenericApplicationContext();
        new XmlBeanDefinitionReader(context2).loadBeanDefinitions("spring-config.xml");
        context2.refresh();
        HelloWorld context2Bean = context2.getBean("helloWorld", HelloWorld.class);
        context2Bean.sayHello();
    }
}
